﻿using SuperJoe.Framework.Core.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WWX.Model;

namespace WWX.Admin.Web.Models
{
    public class MemberVM
    {
        public string Id { get; set; }
        public string Account { get; set; }

        public string Phone { get; set; }

        public string NickName { get; set; }

        public string TrueName { get; set; }

        public DateTime? RegisterDate { get; set; }

        public string Pwd { get; set; }

        public bool? IsActive { get; set; }

        public string Remark { get; set; }

        public string Address { get; set; }

        public void Validate()
        {
            if (Account.IsNullOrWhiteSpace())
            {
                ThrowHelper.ThrowFriendlyException("请输入会员账号");
            }
        }

        public Member ToMember()
        {
            return new Member()
            {
                IsActive = IsActive.Value,
                Id = this.Id,
                Phone = this.Phone,
                Account = this.Account,
                NickName = this.NickName,
                TrueName = this.TrueName,
                RegisterDate = RegisterDate == null ? DateTime.Now : RegisterDate.Value,
                Pwd = this.Pwd,
                Remark= this.Remark,
                Address= this.Address
            };
        }
    }
}